using System;
using System.Windows.Forms;
using CastleSample.Core;

namespace CastleSample.UI.Core
{
    public class ApplicationContainer
    {
        static ApplicationContainer()
        {
            m_Instance = ServiceLocator.Get<ApplicationContainer>();
        }

        private static ApplicationContainer m_Instance;

        public static ApplicationContainer Instance
        {
            get { return m_Instance; }
            set { m_Instance = value; }
        }

        private IEventBroker m_EventBroker;

        public IEventBroker EventBroker
        {
            get { return m_EventBroker; }
            set { m_EventBroker = value; }
        }

        private MainFrame m_MainFrame;

        public MainFrame MainFrame
        {
            get { return m_MainFrame; }
            set { m_MainFrame = value; }
        }

        private IModuleManager m_ModuleManager;

        public IModuleManager ModuleManager
        {
            get { return m_ModuleManager; }
            set { m_ModuleManager = value; }
        }

        public void Start()
        {
            ModuleManager.LoadAllModules();
            MainFrame.Shown += new EventHandler(MainFrame_Shown);
            Application.Run(MainFrame);
        }

        private void MainFrame_Shown(object sender, EventArgs e)
        {
            ModuleManager.StartAllModules();
        }
    }
}